public class Solution101 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        return dfs(root.left,root.right);
    }

    private boolean dfs(TreeNode left, TreeNode right) {
        if (left==null && right==null){
            return true;
        }
        if (left!=null && right!=null){
            return left.val==right.val && dfs(left.left,right.right) && dfs(left.right,right.left);
        }else{
            return false;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution101().isSymmetric(new TreeNode(1,new TreeNode(2,new TreeNode(3),new TreeNode(4)),new TreeNode(2,new TreeNode(4),new TreeNode(3)))));
    }
}
